package com.dianping.cat.consumer.event.model.transform;

import com.dianping.cat.consumer.event.model.IEntity;
import com.dianping.cat.consumer.event.model.IVisitor;
import com.dianping.cat.consumer.event.model.entity.EventName;
import com.dianping.cat.consumer.event.model.entity.EventReport;
import com.dianping.cat.consumer.event.model.entity.EventType;
import com.dianping.cat.consumer.event.model.entity.GraphTrend;
import com.dianping.cat.consumer.event.model.entity.Machine;
import com.dianping.cat.consumer.event.model.entity.Range;
import com.dianping.cat.consumer.event.model.entity.StatusCode;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  17 */   private Stack<Object> m_objs = new Stack();

  private EventReport m_eventReport;


  public DefaultMerger() {}

  public DefaultMerger(EventReport eventReport) {
    this.m_eventReport = eventReport;
/*  26 */     this.m_objs.push(eventReport);
  }


/*  30 */   public EventReport getEventReport() { return this.m_eventReport; }



/*  34 */   protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  38 */     this.m_objs.push(to);
/*  39 */     from.accept(this);
/*  40 */     this.m_objs.pop();
  }

  protected void mergeEventReport(EventReport to, EventReport from) {
/*  44 */     to.mergeAttributes(from);
/*  45 */     to.getDomainNames().addAll(from.getDomainNames());
/*  46 */     to.getIps().addAll(from.getIps());
  }


/*  50 */   protected void mergeGraphTrend(GraphTrend to, GraphTrend from) { to.mergeAttributes(from); }



/*  54 */   protected void mergeMachine(Machine to, Machine from) { to.mergeAttributes(from); }


  protected void mergeName(EventName to, EventName from) {
/*  58 */     to.mergeAttributes(from);
/*  59 */     to.setSuccessMessageUrl(from.getSuccessMessageUrl());
/*  60 */     to.setFailMessageUrl(from.getFailMessageUrl());
  }


/*  64 */   protected void mergeRange(Range to, Range from) { to.mergeAttributes(from); }



/*  68 */   protected void mergeStatusCode(StatusCode to, StatusCode from) { to.mergeAttributes(from); }


  protected void mergeType(EventType to, EventType from) {
/*  72 */     to.mergeAttributes(from);
/*  73 */     to.setSuccessMessageUrl(from.getSuccessMessageUrl());
/*  74 */     to.setFailMessageUrl(from.getFailMessageUrl());
  }


  public void visitEventReport(EventReport from) {
/*  79 */     EventReport to = (EventReport)this.m_objs.peek();

/*  81 */     mergeEventReport(to, from);
/*  82 */     visitEventReportChildren(to, from);
  }

  protected void visitEventReportChildren(EventReport to, EventReport from) {
/*  86 */     for (Machine source : from.getMachines().values()) {
/*  87 */       Machine target = to.findMachine(source.getIp());

/*  89 */       if (target == null) {
/*  90 */         target = new Machine(source.getIp());
/*  91 */         to.addMachine(target);
      }

/*  94 */       this.m_objs.push(target);
/*  95 */       source.accept(this);
/*  96 */       this.m_objs.pop();
    }
  }


  public void visitGraphTrend(GraphTrend from) {
/* 102 */     GraphTrend to = (GraphTrend)this.m_objs.peek();

/* 104 */     mergeGraphTrend(to, from);
/* 105 */     visitGraphTrendChildren(to, from);
  }


  protected void visitGraphTrendChildren(GraphTrend to, GraphTrend from) {}


  public void visitMachine(Machine from) {
/* 113 */     Machine to = (Machine)this.m_objs.peek();

/* 115 */     mergeMachine(to, from);
/* 116 */     visitMachineChildren(to, from);
  }

  protected void visitMachineChildren(Machine to, Machine from) {
/* 120 */     for (EventType source : from.getTypes().values()) {
/* 121 */       EventType target = to.findType(source.getId());

/* 123 */       if (target == null) {
/* 124 */         target = new EventType(source.getId());
/* 125 */         to.addType(target);
      }

/* 128 */       this.m_objs.push(target);
/* 129 */       source.accept(this);
/* 130 */       this.m_objs.pop();
    }
  }


  public void visitName(EventName from) {
/* 136 */     EventName to = (EventName)this.m_objs.peek();

/* 138 */     mergeName(to, from);
/* 139 */     visitNameChildren(to, from);
  }

  protected void visitNameChildren(EventName to, EventName from) {
/* 143 */     for (Range source : from.getRanges().values()) {
/* 144 */       Range target = to.findRange(source.getValue());

/* 146 */       if (target == null) {
/* 147 */         target = new Range(source.getValue());
/* 148 */         to.addRange(target);
      }

/* 151 */       this.m_objs.push(target);
/* 152 */       source.accept(this);
/* 153 */       this.m_objs.pop();
    }

/* 156 */     if (from.getGraphTrend() != null) {
/* 157 */       GraphTrend target = to.getGraphTrend();

/* 159 */       if (target == null) {
/* 160 */         GraphTrend source = from.getGraphTrend();

/* 162 */         target = new GraphTrend(source.getDuration());
/* 163 */         to.setGraphTrend(target);
      }

/* 166 */       this.m_objs.push(target);
/* 167 */       from.getGraphTrend().accept(this);
/* 168 */       this.m_objs.pop();
    }

/* 171 */     for (StatusCode source : from.getStatusCodes().values()) {
/* 172 */       StatusCode target = to.findStatusCode(source.getId());

/* 174 */       if (target == null) {
/* 175 */         target = new StatusCode(source.getId());
/* 176 */         to.addStatusCode(target);
      }

/* 179 */       this.m_objs.push(target);
/* 180 */       source.accept(this);
/* 181 */       this.m_objs.pop();
    }
  }


  public void visitRange(Range from) {
/* 187 */     Range to = (Range)this.m_objs.peek();

/* 189 */     mergeRange(to, from);
/* 190 */     visitRangeChildren(to, from);
  }


  protected void visitRangeChildren(Range to, Range from) {}


  public void visitStatusCode(StatusCode from) {
/* 198 */     StatusCode to = (StatusCode)this.m_objs.peek();

/* 200 */     mergeStatusCode(to, from);
/* 201 */     visitStatusCodeChildren(to, from);
  }


  protected void visitStatusCodeChildren(StatusCode to, StatusCode from) {}


  public void visitType(EventType from) {
/* 209 */     EventType to = (EventType)this.m_objs.peek();

/* 211 */     mergeType(to, from);
/* 212 */     visitTypeChildren(to, from);
  }

  protected void visitTypeChildren(EventType to, EventType from) {
/* 216 */     for (EventName source : from.getNames().values()) {
/* 217 */       EventName target = to.findName(source.getId());

/* 219 */       if (target == null) {
/* 220 */         target = new EventName(source.getId());
/* 221 */         to.addName(target);
      }

/* 224 */       this.m_objs.push(target);
/* 225 */       source.accept(this);
/* 226 */       this.m_objs.pop();
    }

/* 229 */     if (from.getGraphTrend() != null) {
/* 230 */       GraphTrend target = to.getGraphTrend();

/* 232 */       if (target == null) {
/* 233 */         GraphTrend source = from.getGraphTrend();

/* 235 */         target = new GraphTrend(source.getDuration());
/* 236 */         to.setGraphTrend(target);
      }

/* 239 */       this.m_objs.push(target);
/* 240 */       from.getGraphTrend().accept(this);
/* 241 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/event/model/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */